﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CharacterTrailLibrary.Persist.BLL.Model;

namespace CharacterTrailClient.Controls
{
    public class BarCodeAndNameWrap : IDisposable
    {
        private readonly Control _parentControl = null;
        //private bool _isDraw = false;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="parentControl">父面板控件</param>
        public BarCodeAndNameWrap(Control parentControl)
        {
            BarCodeAndNameObject = new BarCodeAndName();
            BarCodeAndNameObject.TextBoxInputBarCodeValidatedEnd += BarCodeAndNameObject_BarCodeInputEnd;
            _parentControl = parentControl;
            IsTheLastControl = false;
        }

        public void Dispose()
        {
            if (BarCodeAndNameObject != null)
            {
                if (! BarCodeAndNameObject.IsDisposed)
                {
                    BarCodeAndNameObject.TextBoxInputBarCodeValidatedEnd -= BarCodeAndNameObject_BarCodeInputEnd;
                    BarCodeAndNameObject.Dispose();
                }
            }
        }

        //public TBomEntryModel FBomEntryModel
        //{
        //    get { return BarCodeAndNameObject.FBomEntryModel; }
        //    set { this.BarCodeAndNameObject.FBomEntryModel = value; }
        //}

        //public TBomMainModel FBomMainModel
        //{
        //    get { return BarCodeAndNameObject.FBomMainModel; }
        //    set { this.BarCodeAndNameObject.FBomMainModel = value; }
        //}

        private void BarCodeAndNameObject_BarCodeInputEnd(BarCodeAndName barCodeAndName, lmbcprintlogModel printlogModel)
        {
            if(this.NextBarCodeAndNameWrapObject != null)
            {
                if (this.BarCodeAndNameObject.InputBarCodeIsOk)
                {
                     NextBarCodeAndNameWrapObject.BarCodeAndNameObject.Focus();
                }
            }
        }

        /// <summary>
        /// 是否是最后一个控件
        /// </summary>
        public bool IsTheLastControl
        {
            get { return this.BarCodeAndNameObject.IsTheLastControl; }
            set { this.BarCodeAndNameObject.IsTheLastControl = value; }
        }

        public void DrawBarCodeAndName()
        {
            if (BarCodeAndNameObject != null)
            {
                _parentControl.Controls.Add(BarCodeAndNameObject);
                BarCodeAndNameObject.Location = new Point(PositionX, PositionY);
                BarCodeAndNameObject.Show();
                //_isDraw = true;
            }
        }

        public string ChildItemName
        {
            get { return this.BarCodeAndNameObject.FName; }
            set{ this.BarCodeAndNameObject.FName = value;}
        }

        public int Index
        {
            get { return this.BarCodeAndNameObject.Index; }
            set { this.BarCodeAndNameObject.Index = value; }
        }

        /// <summary>
        /// 该空间的坐标X
        /// </summary>
        public int PositionX { get; set; }

        /// <summary>
        /// 该空间的坐标Y
        /// </summary>
        public int PositionY { get; set; }

        /// <summary>
        /// 编辑控件对象
        /// </summary>
        public BarCodeAndName BarCodeAndNameObject { get; private set; }

        /// <summary>
        /// 下一个编辑控件对象封装，如果为空，就为最后一个
        /// </summary>
        public BarCodeAndNameWrap NextBarCodeAndNameWrapObject { get; set; }
    }
}
